import http from '../api/http'
import type { ApiResult, PageResult } from './types'

// 门店响应类型（与后端 StoreRequestDto 字段对齐，尽量可选以兼容）
export interface StoreResponse {
  id?: string
  merchantId?: string
  name?: string
  storeCode?: string
  address?: string
  detailedAddress?: string
  creationTime?: string
  contactPerson?: string
  contactPhone?: string
  enableStatus?: number
  storeType?: number
  settlementCycle?: number
  extraProperties?: string
  thumbnailUrl?: string
  location?: string
  // 列表接口附加的成员信息
  bindUserId?: string[]
  bindUserName?: string[]
}

export class StoreService {
  // 获取门店列表（分页）
  static async getStoreList(page: number = 1, limit: number = 10, key: string = '', merchantId?: string): Promise<ApiResult<PageResult<StoreResponse>>> {
    const params: any = { page, limit, key }
    if (merchantId) params.merchantId = merchantId
    const resp = await http.get<ApiResult<PageResult<StoreResponse>>>('/Organization/GetStoreList', { params })
    return resp.data
  }

  // 获取单个门店详情（注意后端参数名为 Id）
  static async getStoreDetail(id: string): Promise<ApiResult<StoreResponse>> {
    const resp = await http.get<ApiResult<StoreResponse>>('/Organization/GetStoreDetail', { params: { Id: id } })
    return resp.data
  }
}

